home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / CGIshell 1.3.2 / Pocket 6.5 / Documents / Some Questions Answered < prev   
Text File  |  1995-11-11  |  8KB  |  202 lines

  1. Are there any books about this?
  2. To learn Forth: _Starting FORTH_ by Leo Brodie          (ISBN 0-13-843079-9).
  3.   Some other Forth books that I have read are:
  4.     _Thinking FORTH_ also by Brodie                             (ISBN 0-13-917568-7)
  5.     _Forth Fundamentals_ by McCabe                             (ISBN 0-88056-091-6)
  6.     _Library of Forth Routines and Utilities_ by Terry  (ISBN 0-452-25841-3)
  7.     _Threaded Interpretive Languages_ by Loeliger       (ISBN 0-07-038360-X)
  8.     _Dr Dobbs Toolbook of Forth_ by Dr. Dobbs              (ISBN 0-934375-41-0)
  9.  
  10. Here are some books that apply to Macintosh assembly or toolbox
  11. programming:
  12.   _Inside Macintosh_, many volumes, by Apple Computer, Addison Wesley
  13.   _Apple Numerics Manual_ by Apple Computer, Addison Wesley
  14.   _Macintosh Revealed_ vols 1-4 by Stephen Chernicoff, Hayden Books
  15.   _M68000 16/32-Bit Microprossor Programmer's Reference Manual_,
  16.     Motorola Inc.
  17.   _The Complete Book of Macntosh Assembly Language Programming_,
  18.     vol 1 and 2 by Dan Weston, Scott Foresman and Company
  19.   _How to Write Macintosh Software_, by Scott Knaster, Addison Wesley
  20.   _Macintosh Programming Secrets_, by Scott Knaster and Keith Rollin,
  21.     Addison Wesley
  22.   _System 7 Revealed_ by Anthony Meadow, Addison Wesley
  23.   _Programming for System 7_ by Gary Little and Tim Swihart, Addison
  24.     Wesley
  25.  
  26. _____________________________________
  27. How can I make a stand alone program with Pocket Forth?
  28. To make a Turnkey application
  29.   1) Make a copy of the Pocket Forth application.  Rename it.
  30.  
  31.   2) Add resources that your application will need to the copy with
  32. Resedit or equivalent. (Since you may have to do this several times, it
  33. is convienent to put all the necessary resources into a file for safe
  34. keeping.)
  35.  
  36.   3) Run Pocket Forth and extend the language to handle whatever task
  37. you want your application to do.  Write an event loop as demonstrated in
  38. the Turnkey section of the manual.  Debug your code interactivly at this
  39. point.
  40.  
  41.   4) Assign handlers to the pertinant event variables and set other
  42. variables to their default values.  See the Events section of the
  43. manual.
  44.  
  45.   5) Finally save the Pocket Forth dictionary from the File menu or just
  46. type save.  Quit Pocket Forth
  47.  
  48.   If all goes well, great, you've just created a program with Pocket
  49. Forth.  If the program crashes or otherwise functions incorrectly, start
  50. over, but spend more time with step 3.
  51.  
  52.   6) When finally the program works as you like, go back to resedit,
  53. change the icons, BNDL, FREF, and creator signature, as well as the
  54. balloon help resources.
  55.  
  56.   That's about it. There is a trivial example in the manual, and a more
  57. complex example with the Read Me application.  The source is in the
  58. example file, reader. The Contributions folder has many other examples.
  59.  
  60. _____________________________________
  61. How does Pocket Forth compile code?
  62. How Dictionary entries are defined:
  63.   Pocket Forth stores its own code in a DICT resource. The
  64. DICT contains machine language and compiled data. For
  65. example a word like '+' compiles a header:
  66.     DC.B  1,'+',0,0  
  67. which is the number of characters followed by the first three
  68. characters of the word's name. If the name is less than three
  69. characters (as in this case), zeros are compiled to fill the
  70. four byte name field. (Only the 5 lsb's count for the length,
  71. with the other bytes providing flags for the compiler to use.)
  72.  
  73.   Then a two byte link field is compiled:
  74.     DC.W  {relative address of the previous word in the list}
  75. This field is used to search the dictionary for a word.
  76.  
  77.   Next comes machine code to implement the word:
  78.     MOVE  (A6)+,D0  ; A6 is the parameter stack pointer
  79.     ADD   D0,(A6)
  80.     RTS
  81. Notice the code ends with RTS. This is because the inner
  82. interpreter of Pocket Forth is nothing more than the JSR/RTS
  83. mechanism built into the processor. That also means that words
  84. can only be pure machine code.
  85.  
  86. _____________________________________
  87. How do I draw curves with Pocket Forth.
  88. Here then is an excerpt from the Bezier code that draws Bezier curves.
  89.   Just paste the following code into the Pocket Forth window then type
  90.  
  91. TEST
  92.  
  93. to run the program:
  94.  
  95. -------------------------Cut Here------------------------------------
  96.  
  97. ( BCurves  Mon May 2, 1988 15:17:20 )
  98. ( the cubic bezier algorithm is from an article by )
  99. ( R. H. Turpin in MICRO no. 70 )
  100. ( Minimalized for clarity 10/28/93 )
  101.  
  102. 2variable P0  \    Start point
  103. 2variable P1   \   Start Control point
  104. 2variable P2    \  End control point
  105. 2variable P3     \ End point
  106.  
  107. 2variable P0' 2variable P1'
  108. 2variable P2' 2variable P3'
  109. variable N
  110.  
  111. ( point math )
  112. : P- ( h0 v0 h1 v1 -- h0-h1 v0-v1 )
  113.     rot swap - rot rot - swap ;
  114. : P* ( h v n -- n*h n*v ) rot over * rot rot * ;
  115. : P*/ ( h v m n -- m*h/n m*v/n )
  116.     rot >r over over 2>r */  ( m*h/n )
  117.     2r> r> swap */ ;  ( m*v/n )
  118.  
  119. : COMPUTE.P' ( -- ) \ fill in the primed variables
  120.     p1 2@ p0 2@ p- 3 p*
  121.     2dup  p2 2@ p1 2@ p- 3 p*
  122.     2dup  p3 2@ p0 2@ p- 2swap p-
  123.     p3' 2!  2swap p- p2' 2!
  124.     p1' 2!  p0 2@ p0' 2! ;
  125.  
  126. : POINTS ( -- h0' v0' h1' v1' h2' v2' h3' v3' )  \ get primed points
  127.     p0' 2@ p1' 2@ p2' 2@ p3' 2@ ;
  128. : P[T] ( p0' p1' p2' p3' t -- h[t] v[t] )  \ t= the step number
  129.     3 0 DO dup >r n @ p*/ d+ r> LOOP drop ;
  130.  
  131. : FIX.N ( -- )  \ set the number of steps
  132.     points 2 n !  1 p[t]
  133.     p0 2@ p-  abs swap abs max
  134.     3 max  100 min  n ! ;
  135.  
  136. : >P0 ( -- ) p0 2@ !pen ;  \  put the pen at the start point
  137. : CURVE ( -- )  \ draw from point to point 
  138.     @pen                 \    hold the pen location
  139.     >p0  n @ 1+  1 DO     \   repeat the following with r=1 to n+1
  140.       points  r p[t]  -to  \  calculate and draw to the next point
  141.     LOOP !pen ;             \ restore the pen location
  142.  
  143. : BDRAW ( -- )  \ draw the curve described in P0,P1,P2,P3
  144.     compute.p'  fix.n  curve  ;
  145.  
  146. : TEST  ( Set points, then draw )
  147.      300  50 p0 2!  \     start point
  148.     -100 150 p1 2!   \    start control
  149.      500 200 p2 2!    \   end control
  150.       75  20 p3 2!     \  end point
  151.     page bdraw ;        \ draw the curve
  152.  
  153.  
  154. ---------------------------Cut To Here-------------------------------
  155.  
  156. _____________________________________
  157. How are menus added?
  158. How to add menus:
  159.   1.  Make a COPY of Pocket Forth and open it with ResEdit.
  160.   2.  First create a new menu resource.
  161.   3.  Then set the menu resource number to 4 (press cmd-I).
  162.   4.  You get a dialog to update the menu id to 4.  Say yes!
  163.   5.  Type in a menu title and add a menu item (cmd-K).
  164.   6.  Title the item and add a cmd key and color if you like.
  165.   7.  Quit ResEdit saving the _COPY_ of Pocket Forth.
  166.   8.  Run the doctored copy of Pocket Forth.
  167.   9.  Paste in the following code:
  168.  
  169. +++++++++++++++>> CUT FROM THE NEXT LINE <<+++++++++++++++++++
  170.  
  171. ( Menu example         Eek-lips day 4 Jan 1992. )
  172. : util beep beep beep ;     ( this represents your menu code )
  173.  
  174. create UteMenu         ( a list of words for your menu items )
  175.     ' util ,            ( there is just one item, see above. )
  176.  
  177. create NewMenuList         ( a list of lists of your menubar )
  178.     18 +md @ @ ,           ( comma in addr of File menu list )
  179.     18 +md @ 2+ @ ,        ( ditto for Edit menu list )
  180.     UteMenu ,              ( and now Your menu )
  181.  
  182. 2variable nmenuh           ( to hold the handle to the menu  )
  183.  
  184. : close  ( Menus leave memory blocks that must be cleaned up )
  185.     nmenuh 2@ 2>r  ,$ A9A3  ( _ReleaseResource )
  186.     [ 22 +md @ compile         ( do the regular quit routine )
  187.     ' close 22 +md !           ( store the new close routine )
  188.  
  189. : +menu                               ( Turn the new menu on.)
  190.     NewMenuList 18 +md !        ( store the new menubar list )
  191.     0 0 2>r 4 >r ,$ A9BF  ( _GetRMenu )
  192.     2r> 2dup 2>r 0 >r ,$ A935  ( _InsertMenu )
  193.     nmenuh 2!  ,$ A937 ;  ( _DrawMenuBar )
  194.  
  195. +menu
  196.  
  197. ++++++++++++++>> CUT TO THE PREVIOUS LINE <<++++++++++++++++++
  198.  
  199. _____________________________________
  200. Why did I do this?
  201. Because it wasn't there.
  202.